<?php
include_once 'DbTools.php';
$username = $_POST['username'];
$password = $_POST['password'];
$newurl = '';
$msg = '';
//连接数据库
$conn = new mysqli();
$conn->connect('127.0.0.1','root','root','bankes');
if(!empty($conn->connect_error)){
    echo'数据库连接错误：'.$conn->connect_error;
    die;
}else{
    echo '数据库连接成功<br/>';
    DbTools::setCoon($conn);
    $data = DbTools::select("select * from bankcard where CardNo=$username and CardPwd=$password");
    if($data == null){
        echo '无效卡或密码';
        $newurl = '登录失败';
        $msg = '/login.php';
    }else{
        $aa = $data['CardNo'];
        $bb = $data['CardPwd'];
        $cc = $data['AccountId'];
        if($username == $aa && $password == $bb){
            $newurl = '登录成功';
            $msg = 'user.php';
            setcookie('userKey',md5($username.$password),time()+24*3600);
            session_start();
            $_SESSION[md5($username.$password)]=[
                'username'=>$username,
                'password'=>$password,
                'AccountId' => $cc
            ];
        }
    }
}
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
<input type="hidden" id="inp1" value="<?php echo $newurl?>">
<input type="hidden" id="inp2" value="<?php echo $msg?>">
</body>
<script type="text/javascript">
    var newurl = document.getElementById('inp1').value;
    var msg = document.getElementById('inp2').value;
    alert(newurl);
    location.href=msg;
</script>
</html>